<?php
/**
 * 授权平台
**/
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='用户管理中心';
include_once './header.php';
?>
<link rel="stylesheet" href="//lib.baomitu.com/toastr.js/latest/css/toastr.min.css">
<?php
$sitecount=$DB->count("SELECT count(*) from authguao_site WHERE uid='{$userrow['uid']}'");
$usercount=$DB->count("SELECT count(*) from authguao_user WHERE upuid='{$userrow['uid']}'");
$invitecount=$DB->count("SELECT count(*) from authguao_invitelog WHERE uid='{$userrow['uid']}'");
$invitemoney=$DB->count("SELECT sum(money) from authguao_invitelog WHERE uid='{$userrow['uid']}'");
$remotecount=$DB->count("SELECT count(*) from authguao_log WHERE uid='{$userrow['uid']}' AND type='异地登录'");
$program = $DB->get_row("select * from authguao_program where id='" . $userrow['proid'] . "' limit 1");
$moneycount=$DB->count("SELECT sum(money) FROM authguao_invitelog WHERE uid='{$userrow['uid']}' AND prize=0");
if ($program) {
    $proname = $program['name'];
} else {
    $proname = '未知程序';
}
$carousel = explode(',', $conf['user_carousel']);
$day = date("Y-m-d");
$lastday = date("Y-m-d",strtotime("-1 day"));
if ($row = $DB->get_row("SELECT * FROM authguao_qiandao WHERE uid='{$userrow['uid']}' and date='$day' order by id desc limit 1")) {
    $isqiandao = true;
    $continue = $row['continue'];
}else{
    if ($row = $DB->get_row("SELECT * FROM authguao_qiandao WHERE uid='{$userrow['uid']}' and date='$lastday' order by id desc limit 1")) {
        $continue = $row['continue'];
    }else{
        $continue = 0;
    }
    $isqiandao = false;
}
/**
 * 小提示
 */
$tpis_arr = [ '小提示：邀请好友注册，购买授权认证权限可赚钱！', '小提示：可以通过上架商品赚钱哦！', '小提示：竞猜娱乐也可以赚钱哦！', '小提示：若是看上什么需要的东西,您可以直接购买！',];
$tpis = $tpis_arr[array_rand($tpis_arr, 1)];
$rs=$DB->query("SELECT * FROM authguao_invitelog WHERE uid='{$userrow['uid']}' order by id desc");
?>
<?php
if ($_GET['act'] == 'notification') {
    if($userrow['power']==3){
        $type = array(0,2,3);
    }elseif($userrow['power']==2){
        $type = array(0,2,4);
        $types = array(6);
    }elseif($userrow['power']==1){
        $type = array(0,2,5);
        $types = array(7);
    }else{
        $type = array(0,1);
    }
    $id=isset($_GET['id'])?intval($_GET['id']):showmsg('警告', '参数错误！', 2, './');
    $row=$DB->get_row("select * from authguao_message where id='$id' and active=1 limit 1");
    if(!$row)
        showmsg('警告', '当前消息不存在！', 2, './');
    if(!in_array($row['type'],$type))
        showmsg('警告', '你没有权限查看此消息内容！', 2, './');
    if($userrow['power']>0 || $userrow['power']<3){
        if($row['type']>5){
            if($userrow['proid']==$row['proid'] && !in_array($row['type'],$types)){
                showmsg('警告', '你没有权限查看此消息内容！', 2, './');
            }
        }
    }
    if(!in_array($id,explode(',',$userrow['msgread']))){
        $msgread_n = $userrow['msgread'].$id.',';
        $DB->query("UPDATE authguao_message SET count=count+1 WHERE id='$id'");
        $DB->query("UPDATE authguao_user SET msgread='".$msgread_n."' WHERE uid='{$userrow['uid']}'");
    }
?>
<style>.imagtes img{max-width: 100%;display: block;margin:auto;}</style>
<div class="wrapper" style="padding: 1em">
    <div class="row">
        <div class="col-xl-6 m-auto text-left">
            <div class="card">
                <h5 class="card-header bg-success text-white"><?php echo $row['title']?></h5>
                <div class="card-body imagtes">
                    <p class="card-text font-16"><?php echo $row['content']?><p><br></p><br><br><hr>你好:平台用户<br><span class="font-14 text-secondary">发布时间：<?php echo $row['addtime']?></span><br>已读用户：<?php echo $row['count']?>人 <img src="//q.qlogo.cn/headimg_dl?dst_uin=<?php echo $admin_qq;?>&spec=640" width="16" />
                    </p><a href="javascript:history.back(-1)" class="btn btn-outline-success btn-sm btn-block">返回上一页</a>
                </div>
                <!-- end card-body-->
            </div>
            <!-- end card-->
        </div>
        <!-- end col-->
    </div>
</div>
<?php }else{ ?>
<div class="row">
    <div class="col-xl-4">
        <div class="card d-block pt-2 pb-1 text-center">
            <img class="card-img-top m-auto" style="height: 68px;width: 68px;margin:auto;display: block;border-radius: 0.3em;box-shadow: 0px 0px 30px #ccc" src="//q4.qlogo.cn/headimg_dl?dst_uin=<?php echo $userrow['qq'];?>&spec=640" alt="Card image cap">
            <div class="card-body pb-2">
                <h5 class="card-title">平台官方认证用户</h5>
                <p class="card-text text-success"><?php echo qqname($userrow['qq']) ?> [ UID:<?php echo $userrow['uid'] ?> / 官方用户 ]</p>
            </div>
            <ul class="list-group list-group-flush mb-2">
                <li class="list-group-item"><?php echo $tpis ?></li>
                <?php if($userrow['power']>0 && $userrow['power']<3){?>
                <li class="list-group-item"><?php echo $proname ?></li>
                <?php }?>
                <li class="list-group-item"><?php echo $remotecount ?>条异常登录记录，账号切莫外借，否则会自动冻结哦</li>
            </ul>
            <a class="btn btn-outline-danger mb-2" href="qiandao.php"><i class="layui-icon <?php echo $isqiandao == true ? 'layui-icon-rate-solid' : 'layui-icon-rate' ?>"></i> 每日签到</a>
            <a class="btn btn-outline-warning mb-2" href="addsite.php"><i class="layui-icon layui-icon-auz"></i> <?php echo $userrow['power'] == 0 ? '购买授权' : '添加授权' ?></a>
            <a class="btn btn-outline-primary mb-2" href="invite.php"><i class="layui-icon layui-icon-gift"></i> 推广有奖</a>
            <a class="btn btn-outline-success mb-2" href="addshop.php"><i class="layui-icon layui-icon-cart"></i> 上架商品</a>
            <a class="btn btn-outline-dark mb-2" href="guesslist.php"><i class="layui-icon layui-icon-gift"></i> 娱乐竞猜</a>
            <a class="btn btn-outline-warning mb-2" href="record.php"><i class="layui-icon layui-icon-rmb"></i> 收支明细</a>
            <a class="btn btn-outline-info mb-2" href="set.php?mod=row"><i class="layui-icon layui-icon-username"></i> 个人信息</a>
            <a class="btn btn-outline-success mb-2" href="recharge.php"><i class="layui-icon layui-icon-rmb"></i> 在线充值</a>
            <a class="btn btn-outline-secondary mb-2" href="login.php?logout"><i class="layui-icon layui-icon-logout"></i> 退出登陆</a>
        </div> <!-- end card-->
    </div>
    <?php if($conf['adver_open']==1){?>
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mb-4">广告推荐</h4>
                <?php if($conf['user_carousel_open']==1 && $conf['user_carousel']){?>
                    <div class="layui-carousel" id="carousel">
                        <div carousel-item>
                        <?php
                        foreach($carousel as $image){
                            echo '<div><img src="'.$image.'"></div>';
                        }
                        ?>
                        </div>
                    </div>
                    <div></br></div>
                <?php }else{?>
                    <center><img src="../assets/img/tui.png" height="37" draggable="false"></center>
                <?php }?>
                <?php
                $rs=$DB->query("SELECT * FROM authguao_adver WHERE active=1 and see=1 order by top asc,id asc");
                while($res = $DB->fetch($rs))
                {
                if (strtotime($res['last']) > TIMESTAMP){
                    if($res['active']==1){
                        echo '<div class="list-group-item">';
                        if($res['top']==1){
                            echo '<img src="../assets/icon/zhiding.gif" draggable="false"> ';
                        }
                        if($res['icon']==1){
                            $icon="<img src='../assets/icon/tuij.gif' draggable='false'>";
                        }elseif($res['icon']==2){
                            $icon="<img src='../assets/icon/tj.gif' draggable='false'>";
                        }elseif($res['icon']==3){
                            $icon="<img src='../assets/icon/vip.gif' draggable='false'>";
                        }elseif($res['icon']==4){
                            $icon="<img src='../assets/icon/jing.gif' draggable='false'>";
                        }elseif($res['icon']==5){
                            $icon="<img src='../assets/icon/hoot.gif' draggable='false'>";
                        }elseif($res['icon']==6){
                            $icon="<img src='../assets/icon/zs.gif' draggable='false'>";
                        }elseif($res['icon']==7){
                            $icon="<img src='../assets/icon/hg.gif' draggable='false'>";
                        }elseif($res['icon']==8){
                            $icon="<img src='../assets/icon/hot.gif' draggable='false'>";
                        }elseif($res['icon']==9){
                            $icon="<img src='../assets/icon/guan.png' draggable='false'>";
                        }elseif($res['icon']==10){
                            $icon="<img src='../assets/icon/rz.png' draggable='false'>";
                        }elseif($res['icon']==11){
                            $icon="<img src='../assets/icon/hot.png' draggable='false'>";
                        }elseif($res['icon']==12){
                            $icon="<img src='../assets/icon/zan.png' draggable='false'>";
                        }else{
                            $icon=null;
                        }
                        echo '<span style="color:'.$res['colour'].'">'.$res['title'].' '.$icon.'</span><span onclick="layer.confirm(\'将跳转至赞助商广告，请注意防骗！\',{title:\'提示\',btn: [\'确定\',\'取消\']}, function(){window.location.href = \''.$res['url'].'\';});" class="layui-btn layui-btn-xs layui-btn-radius pull-right">访问网站</span></div>';
                    }
                }
            }
            ?>
            </div>
            <!-- end card-body -->
        </div>
        <!-- end card-->
    </div>
    <?php }?>
    <div class="col-xl-8">
        <div class="row">
            <div class="col-xl-12">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;" onclick="layer.alert('QQ互联绑定可用作账号登陆！',{icon:3,title:'QQ互联绑定',btn:['确定','重新绑定'],btn2:function(layero,index) { window.open('binding.php') }})">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-login-qq widget-icon" style="background-color: #494951;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">QQ互联</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo ($userrow['access_token'] == '' ? '点击绑定' : $userrow['nickname']) ?></h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-cellphone widget-icon" style="background-color: #02cbe4;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">注册时间</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $userrow['addtime'] ?></h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
        </div> <!-- end row -->
        <div class="row">
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-rmb widget-icon" style="background-color: #ff0a24;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">余额 <a href="recharge.php" class="badge badge-danger-lighten">充值</a></h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo round($userrow['rmb'], 2) ?>元</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-rate-solid widget-icon" style="background-color: #ff824d;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">可提现余额<?php if($conf['user_tixian']==1){?> <a href="tixian.php" class="badge badge-danger-lighten">提现</a><?php }?></h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo round($userrow['rmb_tc'], 2) ?>元</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-list widget-icon" style="background-color: #ff6ba8;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的授权 <a href="authlist.php" class="badge badge-danger-lighten">管理</a></h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $sitecount?>个</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-vercode widget-icon" style="background-color: #98ff3b;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的下级<?php if($userrow['power']>0){?> <a href="userlist.php" class="badge badge-danger-lighten">管理</a><?php }?></h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $usercount?>个</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
        </div> <!-- end row -->
        <div class="row">
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-component widget-icon" style="background-color: #8ed9ff;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">累计邀请 <a href="invite.php" class="badge badge-danger-lighten">推广</a></h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $invitecount?>人</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-star widget-icon" style="background-color: #a1ccff;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">累计奖励</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo round($invitemoney,2)?>元</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-user widget-icon" style="background-color: #9655d0;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的编号</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $userrow['uid'] ?></h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body"<?php if($userrow['power']<3){?> onclick="layer.alert('等级越高商品价格越便宜哦,当前你的权限为<?php echo $power_name?>！',{title:'权限提示',btn:['确定','提升权限'],btn2:function(layero,index) { location.href='uppower.php' }})"<?php }?>>
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <i class="layui-icon layui-icon-username widget-icon" style="background-color: #43A047;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">当前权限</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $power_name?></h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
        </div> <!-- end row -->
    </div>
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mb-4">平台通知</h4>
                <div class="slimscroll" style="max-height: 230px;">
                    <?php foreach($msgrow as $row){ ?>
                        <a href="index.php?act=notification&id=<?php echo $row['id'] ?>" class="dropdown-item notify-item pb-0">
                            <p class="notify-details"><span class="text-truncate mr-3"><?php echo $row['title'] ?></span>
                                <?php if ($row['read']) { ?>
                                    <span class="badge badge-success-lighten">已读</span><br>
                                <?php } else { ?>
                                    <span class="badge badge-danger-lighten">未读</span><br>
                                <?php } ?>
                                <span class="text-muted"><?php echo $row['addtime'] ?></span>
                            </p>
                        </a>
                    <?php } ?>
                    <?php if($userrow['power']>0 && $userrow['power']<3){?>
                    <?php foreach($msgrows as $row){ ?>
                        <a href="index.php?act=notification&id=<?php echo $row['id'] ?>" class="dropdown-item notify-item pb-0">
                            <p class="notify-details"><span class="text-truncate mr-3"><?php echo $row['title'] ?></span>
                                <?php if ($row['read']) { ?>
                                    <span class="badge badge-success-lighten">已读</span><br>
                                <?php } else { ?>
                                    <span class="badge badge-danger-lighten">未读</span><br>
                                <?php } ?>
                                <span class="text-muted"><?php echo $row['addtime'] ?></span>
                            </p>
                        </a>
                    <?php }} ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mb-4">我的邀请</h4>
                <div class="slimscroll" style="max-height: 230px;">
                    <?php while($res = $DB->fetch($rs)) { ?>
                        <div class="media p-2 shadow-sm">
                            <img class="mr-3 rounded-circle" src="//q.qlogo.cn/headimg_dl?dst_uin=<?php echo $res['qq'];?>&spec=640" width="40" alt="Generic placeholder image">
                            <div class="media-body">
                                <h5 class="mt-0 mb-1 text-justify"><?php echo qqname($res['qq']) ?></h5>
                                <span class="font-13"><?php echo $res['creation_time'] ?>
                            </span>
                                <?php
                                if ($res['prize'] == 1) {
                                    echo '<a href="javascript:layer.msg(\'您已经在<font color=#03de01>' . $res['draw_time'] . '</font>领取了奖励点!\')" class="badge badge-primary-lighten">您已经领取奖励</a>';
                                } else {
                                    echo '<span class="badge badge-success-lighten" onclick="getprize('.$res['id'].')">点我领取邀请奖励</span>';
                                }
                                ?>
                            </div>
                            <a class="badge badge-warning ml-1 text-white mt-3">待领取：<?php echo round($moneycount,2) ?></a>
                        </div>
                    <?php } ?>
                </div>
            </div>
            <!-- end card-body -->
        </div>
        <!-- end card-->
    </div>
</div>
<!-- end row -->
<?php if (isset($conf['user_notice'])) { ?>
    <div class="col-xl-12 p-0">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mb-4">后台公告</h4>
                <div class="card-body p-0">
                    <?php echo $conf['user_notice'] ?>
                </div>
            </div>
        </div>
    </div>
<?php }} ?>
<?php
include_once './bottom.php';
?>
<script src="//lib.baomitu.com/toastr.js/latest/toastr.min.js"></script>
<script src="//lib.baomitu.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<?php if ($_GET['act'] != 'notification') {?>
<script>
<?php if($isqiandao==false){ ?>
!function (t) {
    t.NotificationApp.send("今天还没签到哦?", "点击签到按钮领取今日的余额,每天都可以领取哦~", "top-right", "rgba(0,0,0,0.2)", "success", !1)
}(window.jQuery);
<?php } ?>
</script>
<?php }?>